/*
 * Texture.h: interface for the dynamic generated texture classes.
 */

#ifndef _TEXTURE_INCLUDE_
#define _TEXTURE_INCLUDE_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <windows.h>

#ifndef PI
#define PI 3.141592653589794
#endif

// RGB struct (custom palette's component).
typedef struct _tagRGB {
	BYTE r, g, b;
}RGB;

// Texture filter.
typedef enum{
	NEAREST=0, LINEAR, MIPMAPPING
}TEX_FILTER;

/***********************************************************
 *    Abstract base class for dynamic generated texture.   *
 ***********************************************************/
class Texture  
{
public:
	// constructor
	Texture();
	// destructor
	virtual ~Texture();

	// initialize texture object.
	virtual BOOL Init(int wdt, int hgt);
	// set texture.
	void SetTexture(TEX_FILTER filter=LINEAR);

	// generate texture data.(pure virtual function.)
	virtual void RenderTexture()=0;

protected:
	int  m_width, m_height;	// texture width and height.
	int  m_texsize;			// texture data buffer size.
	BYTE *m_data;			// texture data buffer.
};


/***********************************************************
 * texture class which fill every texel with random color. *
 ***********************************************************/
class RandomPointTexture : public Texture  
{
public:
	// render texture.
	void RenderTexture();
};


/**********************************************************
 *              Simple plasma texture class.              *
 **********************************************************/
class PlasmaTexture : public Texture  
{
public:
	PlasmaTexture();
	~PlasmaTexture();

	// initialize plasma texture object.
	BOOL Init(int wdt, int hgt);
	// render texture.
	void RenderTexture();

private:
	// methods
	void InitPlasma();
	void UpdatePalette();

	// members
	RGB  m_palette[256];
	BYTE *m_plasma1;
	BYTE *m_plasma2;
};


/**********************************************************
 *                  Fire texture class.                   *
 **********************************************************/
class FireTexture : public Texture  
{
public:
	FireTexture();
	~FireTexture();

	// initialize plasma texture object.
	BOOL Init(int wdt, int hgt);
	// render texture.
	void RenderTexture();

private:
	// methods
	void InitPalette();
	void ShadePalette(BYTE beg, BYTE end,
					  BYTE r1,  BYTE g1,  BYTE b1,
					  BYTE r2,  BYTE g2,  BYTE b2);

	void PutRndPoints();
	void BurnBuf();

	void SwapBufPointers(){	\
		BYTE *temp=m_fire1;	\
		m_fire1=m_fire2;	\
		m_fire2=temp;		\
	};

	// members
	RGB  m_palette[256];
	BYTE *m_fire1;
	BYTE *m_fire2;

	int  m_cxBuf, m_cyBuf;
};

#endif // #ifndef _TEXTURE_INCLUDE_